import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Put,
  Query,
  Req,
  UseInterceptors,
} from '@nestjs/common';
import { OrgService } from './org.service';
import { PageResult } from '../../common/result/PageResult';
import { SysOrg } from './entities/org.entity';
import { OrgPageQuery } from './dto/org.page.query';
import { Result } from '../../common/result/Result';
import { OrgForm } from './dto/org.form';
import {
  AuthInterceptor,
  RequiredPermission,
} from '../../config/filter/auth.interceptor';

@Controller('/api/v1/org')

export class OrgController {
  constructor(private orgService: OrgService) {}
  @Get('/page')
  @UseInterceptors(AuthInterceptor)
  async page(@Query() query: OrgPageQuery): Promise<PageResult<SysOrg>> {
    const result = await this.orgService.getPage(query);
    return result;
  }

  @Post('add')
  @UseInterceptors(AuthInterceptor)
  @RequiredPermission('sys:role:add')
  async addOrg(@Body() org: OrgForm, @Req() req): Promise<Result<any>> {
    const result = await this.orgService.saveOrg(org, req.user);
    return result;
  }
}